<template>
	<view class="">
		<common-title :title="titleContent" @clickLeft="backToUpPage" @clickRight="editShowDay"></common-title>
		<view class="couple-show-view">
			<radio-group class="couple-show-radio" @change="editTpye">
				<label v-for="(item, index) in showNameType" :key="index" class="couple-show-radio-item">
					<view>{{item.name}}</view>
					<radio :value="item.type" :checked="item.type === selectType" color="#18bc37" borderColor="#fff"></radio>
				</label>
			</radio-group>
		</view>
	</view>
</template>

<script setup>
	import { ref } from "vue";
	import { onLoad } from '@dcloudio/uni-app';
	import { getCoupleInfo } from "../../../../utils/apiMine";
import { setDataToStorage } from "../../../../utils/commonUtils";
	//标题内容
	const titleContent = ref({
		left:'',
		midst:'修改展示',
		right:'保存'
	});
	
	//返回
	const backToUpPage = () => {
		uni.navigateBack();
	};
	//保存修改
	const editShowDay = async () => {
	    // 映射对象，将 selectType 对应到 coupleInfo 的属性
	    const typeToDayMap = {
	        '1': coupleInfo.value.firstMeetDay,
	        '2': coupleInfo.value.confirmLoveDay,
	        '3': coupleInfo.value.weddingDay
	    };
	
	    // 更新 showTimeType
	    const showTimeType = ref({
	        'type': selectType.value,
	        'time': typeToDayMap[selectType.value] || null // 默认值为 null
	    });
	
	    // 保存数据到存储
	    setDataToStorage('showTimeType', showTimeType);
		uni.showToast({
			title:'保存成功'
		})
		uni.redirectTo({
			url:'/pages/mine/other_set/couple-set'
		});
	};
	//---------------------------------修改要展示的日期---------------------------------------------
	const showNameType = ref([
		{'type':'1','name':'第一次见面'},
		{'type':'2','name':'恋爱确认日'},
		{'type':'3','name':'结婚日'}
	]);
	const selectType = ref(null);
	const coupleInfo = ref({
		backgroundPic:null,
		confirmLoveDay:null,
		couplesName:null,
		firstMeetDay:null,
		weddingDay:null
	});
	onLoad( async (options) => {
		selectType.value = options.selectType ? decodeURIComponent(options.selectType) : '';
		// console.log(selectType.value)
		let res = await getCoupleInfo();
		// console.log(res);
		coupleInfo.value = res;
		// console.log(coupleInfo)
	});
	const editTpye = (e) => {
		selectType.value = e.detail.value;
	}
</script>

<style lang="scss" scoped>
	.couple-show-view{
		display: flex;
		justify-content: center;
		align-items: center;
		.couple-show-radio{
			display: flex;
			flex-direction: column;
			width: 690rpx;
			.couple-show-radio-item{
				display: flex;
				justify-content: space-between;
				padding: 20rpx;
				border-bottom: 1px solid #e5e5e5;
				font-size: 36rpx;
			}
		}
	}
</style>